package com.r_z.controller;

import com.alibaba.druid.pool.ha.selector.StickyDataSourceHolder;
import com.r_z.entity.OrderDetails;
import com.r_z.entity.SalesOrder;
import com.r_z.service.SalesOrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author z
 * @version 1.0
 * @date 2023/5/29
 */
@CrossOrigin
@RestController
public class SalesOrderController {
    @Resource
    SalesOrderService salesOrderService;
/**查询销售订单*/
    @GetMapping("selectSalesOrder")
    public HashMap<String,Object> selectSalesOrder(String salesOrderId,int page,int limit){
        List<SalesOrder> salesOrderList =salesOrderService.salesOrderList(salesOrderId,page,limit);
        System.out.println("集合"+salesOrderList);
        int count =salesOrderService.count(salesOrderId);
        System.out.println("查询"+count);
        HashMap<String,Object> saleMap=new HashMap<>();
        saleMap.put("code",0);
        saleMap.put("msg","");
        saleMap.put("data",salesOrderList);
        saleMap.put("count",count);
        return saleMap;
    }
    /**新增销售订单*/
    @PostMapping("/insertSalesOrder")
     public int insertSalesOrder(SalesOrder salesOrder){
        return salesOrderService.insertSalesOrder(salesOrder);
    }
    /**修改销售订单*/
    @PutMapping("/updateSalesOrder")
    public int updateSalesOrder(SalesOrder salesOrder){
        return salesOrderService.updateSalesOrder(salesOrder);
    }
    /**删除销售订单*/
   @DeleteMapping("/deleteSalesOrder")
    public int deleteSalesOrder(String salesOrderId){
       return  salesOrderService.deleteSalesOrder(salesOrderId);
   }

    /**
     * 销售订单详情
     * @param salesOrderId
     * @return
     */
    @GetMapping("orders")
    public HashMap<String, Object> orders(String salesOrderId){
        System.out.println("进入销售订单详情");
        List<OrderDetails> OrderList = salesOrderService.OrderDetails(salesOrderId);
        HashMap<String,Object> orderMap=new HashMap<>();
        orderMap.put("code",0);
        orderMap.put("mag","");
        orderMap.put("data",OrderList);
        System.out.println(OrderList);
        orderMap.put("count",10);
        return orderMap;
    }
}
